/**
 * Copyright 2015 ABSir's Studio
 * 
 * All right reserved
 *
 * Create on 2015年10月5日 上午10:51:46
 */
package com.absir.appserv.system.asset;

import java.io.IOException;

import com.absir.appserv.system.bean.JPayTrade;
import com.absir.appserv.system.bean.proxy.JiUserBase;
import com.absir.appserv.system.service.IPlatformIdentity;
import com.absir.appserv.system.service.QianbaoService;
import com.absir.appserv.system.service.utils.PayUtils;
import com.absir.server.in.Input;
import com.absir.server.value.Binder;
import com.absir.server.value.Body;
import com.absir.server.value.Param;
import com.absir.server.value.Server;
import com.fasterxml.jackson.core.JsonProcessingException;

/**
 * @author absir
 *
 */
@Server
public class Asset_qianbao extends AssetServer {

	/**
	 * @param code
	 */
	@Body
	public String author(@Param String code) {
		JiUserBase user = QianbaoService.ME.onLoginCode(code);
		if (user != null) {
			return IPlatformIdentity.PLATFORM_IDENTITY.loginPlatform(user);
		}

		return "fail";
	}

	public static class NotifyData {

		public String merchantTransCode;

		public String qbTransCode;

		public boolean isSuccess;

		public String code;

		public String transTime;

	}

	/**
	 * @param input
	 * @return
	 * @throws Exception
	 */
	@Body
	public String notify(JPayTrade payTrade, @Binder NotifyData data, Input input) throws Exception {
		if (data.isSuccess) {
			payTrade.setPlatform(QianbaoService.PLAT_FORM_NAME);
			PayUtils.proccessDone(payTrade);
			/*
			 * PayData payData = QianbaoService.ME.validator(payTrade.getId(),
			 * data.qbTransCode, data.transTime); //
			 * QianbaoService.QIANBAO_CONFIGURE.isTest() || if ((payData != null
			 * && KernelObject.equals(payData.status, "支付成功"))) {
			 * PayUtils.proccessDone(payTrade); }
			 */
		}

		return "success";
	}

	/**
	 * @param input
	 * @return
	 * @throws JsonProcessingException
	 * @throws IOException
	 */
	@Body
	public String paySuccess(Input input) throws JsonProcessingException, IOException {
		return "success";
	}

}
